<?php
ob_implicit_flush();
include "../Lib/Include.php";
$Domain=$_GET["S"];
$SiteStr="";

$fp = fsockopen("www.alexa.com", 80, $errno, $errstr, 30);
if(!$fp){
	echo "$errstr ($errno)<br />\n";
}else{
	$out = "GET /siteinfo/".str_replace("www.","",$Domain)." HTTP/1.1\r\n" ;
	$out .= "Host: www.alexa.com\r\n" ;
	$out .= "Connection: Close\r\n\r\n" ; 
	fwrite($fp, $out);
	$PageCode="";
	while (!feof($fp)) {
		$PageCode.= fgets($fp, 128);
	}
	fclose($fp); 
}
//获取排名
$Arr=spliti("<td class=\"small\" align=\"center\">Traffic Rank</td>",$PageCode);
$Arr=spliti("</table>",$Arr[1]);
$AlexaData=$Arr[0];
$Arr=spliti("<th>7 day</th>",$AlexaData);
$Arr=spliti("</td>",$Arr[1]);
$Arr=spliti(">",$Arr[0]);
$AlexaDay=$Arr[1];
$Arr=spliti("<th>1 month</th>",$AlexaData);
$Arr=spliti("</td>",$Arr[1]);
$Arr=spliti(">",$Arr[0]);
$AlexaMonth1=$Arr[1];
$Arr=spliti("<th>3 month</th>",$AlexaData);
$Arr=spliti("</td>",$Arr[1]);
$Arr=spliti(">",$Arr[0]);
$AlexaMonth3=$Arr[1];
//排名输出
$SiteStr=$AlexaDay;
$SiteStr.="|||".$AlexaMonth1;
$SiteStr.="|||".$AlexaMonth3;

$Arr=spliti("<td class=\"small\" align=\"center\">Reach</td>",$PageCode);
$Arr=spliti("</table>",$Arr[1]);
$AlexaData=$Arr[0];
$Arr=spliti("<th>1 month</th>",$AlexaData);
$Arr=spliti("</td>",$Arr[1]);
$Arr=spliti(">",$Arr[0]);
$AlexaIp=$Arr[1];
$AlexaIp=$AlexaIp*10000*600;
$Arr=spliti("<td class=\"small\" align=\"center\">Pageviews/User</td>",$PageCode);
$Arr=spliti("</table>",$Arr[1]);
$AlexaData=$Arr[0];
$Arr=spliti("<th>1 month</th>",$AlexaData);
$Arr=spliti("</td>",$Arr[1]);
$Arr=spliti(">",$Arr[0]);
$AlexaPv=$Arr[1];
$AlexaPv=$AlexaIp*$AlexaPv;
$SiteStr.="|||"."IP ≈ ".$AlexaIp." PV ≈ ".$AlexaPv."（一月平均）";
echo $SiteStr;
?>